<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="甲方识别码" prop="ah">
        <el-input
          v-model="queryParams.nbajbh"
          placeholder="请输入甲方识别码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法院" prop="ah">
        <el-input
          v-model="queryParams.fymc"
          placeholder="请输入法院名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案件名称" prop="ajmc">
        <el-input
          v-model="queryParams.ajmc"
          placeholder="请输入案件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="立案方式" prop="lafs">
        <el-select v-model="queryParams.lafs" placeholder="请选择立案方式" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.fs_lafs"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否已邮寄" prop="ifPost">
        <el-select v-model="queryParams.ifPost" placeholder="是否已邮寄" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.fs_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开启还款" prop="ifPost">
        <el-select v-model="queryParams.ifRepayment" placeholder="是否开启还款" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.fs_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="结案状态" prop="ajzt">
        <el-select v-model="queryParams.ajzt" placeholder="请选择结案状态" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.fs_gw_ajzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="立案状态" prop="zt">
        <el-select v-model="queryParams.zt" placeholder="请选择立案状态" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.fs_gw_layyzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="调解员">
        <el-select v-model="queryParams.tjyId" placeholder="请选择调解员" clearable @change="handleQuery">
          <el-option
            v-for="item in tjyOptions"
            :key="item.userId"
            :label="item.nickName"
            :value="item.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="委托方批次">
        <el-select v-model="queryParams.zfid" placeholder="请选择委托方" clearable @change="getBatch">
          <el-option
            v-for="item in zfOptions"
            :key="item.id"
            :label="item.name+'('+item.caseCount+')'"
            :value="item.id"
          ></el-option>
        </el-select>
        <el-select v-model="queryParams.batchId" placeholder="请选择批次" clearable @change="handleQuery">
          <el-option
            v-for="item in pcOptions"
            :key="item.id"
            :label="item.batchName+'('+item.caseCount+')'"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="诉讼主体">
        <el-select v-model="queryParams.ssztid" placeholder="请选择诉讼主体" clearable @change="handleQuery">
          <el-option
            v-for="item in ssztOptions"
            :key="item.id"
            :label="item.dwmc"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="地区">
        <el-select v-model="queryParams.sfid" placeholder="请选择省份" clearable @change="getDs">
          <el-option
            v-for="item in sfOptions"
            :key="item.id"
            :label="item.name+'('+item.caseCount+')'"
            :value="item.id"
          ></el-option>
        </el-select>
        <el-select v-model="queryParams.sid" placeholder="请选择地市" clearable @change="getQx">
          <el-option
            v-for="item in dsOptions"
            :key="item.id"
            :label="item.name+'('+item.caseCount+')'"
            :value="item.id"
          ></el-option>
        </el-select>
        <el-select v-model="queryParams.qxid" placeholder="请选择区县" clearable @change="handleQuery">
          <el-option
            v-for="item in qxOptions"
            :key="item.id"
            :label="item.name+'('+item.caseCount+')'"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportNwd"
          v-hasPermi="['fs:case:export']"
        >导出案件跟进信息
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['fs:case:export']"-->
      <!--        >导出-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="caseList" @selection-change="handleSelectionChange">
      <el-table-column label="甲方识别码" align="center" prop="nbajbh"/>
      <el-table-column label="资产包" align="center" prop="ajmc" width="180px">
        <template slot-scope="scope">
          <span>{{ scope.row.zfName }}</span>
          &nbsp;&nbsp;
          <span>{{ scope.row.batchName }}</span>
          <br>
          <span>{{ scope.row.ssztmc }}</span>
          <br>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleZjcl(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >证据
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="被告" align="center" width="250px">
        <template slot-scope="scope">
          <span>{{ scope.row.bgDsr.xm }}</span>
          &nbsp;&nbsp;
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.bgDsr.xb"/>
          &nbsp;&nbsp;
          <span>{{ scope.row.bgDsr.sjhm }}</span>
          <br>
          <span>{{ scope.row.bgDsr.zjhm }}</span>
          <br>
          <span>{{ scope.row.bgDsr.dz }}</span>
        </template>
      </el-table-column>
      <el-table-column label="诉情金额" align="center" width="120px">
        <template slot-scope="scope">
          <span>{{ (scope.row.sqbdje * 10000).toFixed(2) }}</span>
          <br>
          <span class="cellBtn">
            <el-button title="制定 还款计划"
                       v-if="scope.row.ifRepayment==0"
                       size="mini"
                       type="text"
                       icon="el-icon-circle-plus"
                       @click="handleAddHkjh(scope.row)"
                       v-hasPermi="['fs:case:edit']"
            >
            </el-button>
            <el-button title="查看 还款计划"
                       v-if="scope.row.ifRepayment==1"
                       size="mini"
                       type="text"
                       icon="el-icon-time"
                       @click="handleViewHkjh(scope.row)"
                       v-hasPermi="['fs:case:edit']"
            >
            </el-button>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="立案信息" align="center" width="180px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fs_gw_sqlx" :value="scope.row.sqlx"/>
          <span>{{ scope.row.sqlaayMc }}</span>
          <br>
          <span class="btn" @click="handleSh(scope.row)">
            网立：
            <dict-tag :options="dict.type.fs_gw_layyzt" :value="scope.row.zt"/>
            <dict-tag v-if="scope.row.ajzt != 0" :options="dict.type.fs_gw_ajzt" :value="scope.row.ajzt"/>
          </span>
          <br>
          <dict-tag v-if="scope.row.lafs != 0" :options="dict.type.fs_lafs" :value="scope.row.lafs"/>
        </template>
      </el-table-column>
      <el-table-column label="法院信息" align="center" width="180px">
        <template slot-scope="scope">
          <span>{{ scope.row.fymc }}</span>
          <br>
          <span class="cellBtn">
            <el-button title="添加 法院联系记录"
                       size="mini"
                       type="text"
                       icon="el-icon-circle-plus-outline"
                       @click="handleAddFylxjl(scope.row)"
                       v-hasPermi="['fs:case:edit']"
            >
            </el-button>
            <el-button title="查看 法院联系记录"
                       v-if="scope.row.ifCourtContact==1"
                       size="mini"
                       type="text"
                       icon="el-icon-document"
                       @click="handleViewFylxjl(scope.row)"
                       v-hasPermi="['fs:case:edit']"
            >
            </el-button>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="gxsj" width="85px"/>
      <el-table-column label="归属" align="center" prop="owner" width="120px">
        <template slot-scope="scope">
          <span>律师： {{ scope.row.owner }}</span>
          <br>
          <span>调解员： {{ scope.row.tjy }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邮寄信息" align="center" prop="ifPost">
        <template slot-scope="scope">
          <span v-if="scope.row.ifPost==1" class="btn" @click="handleYjxx(scope.row)">
            <dict-tag :options="dict.type.fs_post_ywlx" :value="scope.row.lastExpress.ywlx"/>
            <br>
            <dict-tag :options="dict.type.fs_post_ywzt" :value="scope.row.lastExpress.ywzt"/>
          </span>
          <span v-if="scope.row.ifPost==0" class="btn" @click="handleYjxx(scope.row)">
            <el-button
              v-if="scope.row.ifPost!=1"
              size="mini"
              type="text"
              icon="el-icon-s-promotion"
              @click="handleYj(scope.row)"
              v-hasPermi="['fs:case:edit']"
            >邮寄补充
            </el-button>
          </span>
          <br>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleYjgd(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >邮寄工单
          </el-button>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"
                       width="180px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleProcess(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >进展
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleJa(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >结案
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-refresh"
            @click="handleAjct(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >重提工单
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改案件信息对话框 -->
    <el-dialog class="detail" :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">
        <el-collapse v-model="activeNames">
          <el-collapse-item title="基本信息" name="1">
            <el-row>
              <el-col :span="24">
                <el-form-item label="接收法院：">{{ form.fymc }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="案件类型：">{{ form.ajlxMc }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="申请类型：">{{ form.sqlxMc }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="标的数额：">{{ form.sqbdje }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="立案案由：">{{ form.sqlaayMc }}</el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item title="原告" name="2">
            <el-row>
              <el-col :span="24">
                <el-form-item label="当事人类型：">
                  <dict-tag :options="dict.type.fs_gw_dsrlx" :value="ygDsr.dsrlx"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="ygDsr.dsrlx==2">
              <el-col :span="12">
                <el-form-item label="单位名称：">{{ ygDsr.dwmc }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="单位性质：">
                  <dict-tag :options="dict.type.fs_gw_dwxz" :value="ygDsr.dwxz"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证照类型：">
                  <dict-tag :options="dict.type.fs_gw_zzlx" :value="ygDsr.zzlx"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证照号码：">{{ ygDsr.zzh }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人姓名：">{{ ygDsr.fddbr }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人职务：">{{ ygDsr.fddbrzw }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人证件类型：">
                  <dict-tag :options="dict.type.fs_gw_zjlx" :value="ygDsr.zjlx"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人证件号码：">{{ ygDsr.zjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人手机号码：">{{ ygDsr.sjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人固定电话：">{{ ygDsr.gddh }}</el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="主要办事地址：">{{ ygDsr.zybsjgszd }}</el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="ygDsr.dsrlx==1">
              <el-col :span="12">
                <el-form-item label="姓名：">{{ ygDsr.xm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件类型：">
                  <dict-tag :options="dict.type.fs_gw_zjlx" :value="ygDsr.zjlx"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件号码：">{{ ygDsr.zjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="性别：">
                  <dict-tag :options="dict.type.sys_user_sex" :value="ygDsr.xb"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="年龄：">{{ ygDsr.nl }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生日期：">{{ ygDsr.csrq }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="民族：">
                  <dict-tag :options="dict.type.fs_gw_mz" :value="ygDsr.mz"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="职业：">
                  <dict-tag :options="dict.type.fs_gw_zy" :value="ygDsr.zy"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工作单位：">{{ ygDsr.gzdw }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="手机号码：">{{ ygDsr.sjhm }}</el-form-item>
              </el-col>
              <el-col :span="16">
                <el-form-item label="地址：">{{ ygDsr.dz }}</el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
          <el-collapse-item title="被告" name="3">
            <el-row>
              <el-col :span="24">
                <el-form-item label="当事人类型：">
                  <dict-tag :options="dict.type.fs_gw_dsrlx" :value="bgDsr.dsrlx"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="bgDsr.dsrlx==2">
              <el-col :span="12">
                <el-form-item label="单位名称：">{{ bgDsr.dwmc }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="单位性质：">
                  <dict-tag :options="dict.type.fs_gw_dwxz" :value="bgDsr.dwxz"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证照类型：">
                  <dict-tag :options="dict.type.fs_gw_zzlx" :value="bgDsr.zzlx"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证照号码：">{{ bgDsr.zzh }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人姓名：">{{ bgDsr.fddbr }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人职务：">{{ bgDsr.fddbrzw }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人证件类型：">
                  <dict-tag :options="dict.type.fs_gw_zjlx" :value="bgDsr.zjlx"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人证件号码：">{{ bgDsr.zjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人手机号码：">{{ bgDsr.sjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法人固定电话：">{{ bgDsr.gddh }}</el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="主要办事机构所在地：">{{ bgDsr.zybsjgszd }}</el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="bgDsr.dsrlx==1">
              <el-col :span="12">
                <el-form-item label="姓名：">{{ bgDsr.xm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件类型：">
                  <dict-tag :options="dict.type.fs_gw_zjlx" :value="bgDsr.zjlx"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="证件号码：">{{ bgDsr.zjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="性别：">
                  <dict-tag :options="dict.type.sys_user_sex" :value="bgDsr.xb"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="年龄：">{{ bgDsr.nl }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生日期：">{{ bgDsr.csrq }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="民族：">
                  <dict-tag :options="dict.type.fs_gw_mz" :value="bgDsr.mz"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="职业：">
                  <dict-tag :options="dict.type.fs_gw_zy" :value="bgDsr.zy"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工作单位：">{{ bgDsr.gzdw }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="手机号码：">{{ bgDsr.sjhm }}</el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="地址：">{{ bgDsr.dz }}</el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 审核弹出框 -->
    <el-dialog :title="shTitle" :visible.sync="shOpen" width="800px" append-to-body>

      <el-table :data="shList">
        <el-table-column label="经办法院" align="center" prop="jbfy"/>
        <el-table-column label="审查人" align="center" prop="shrmc"/>
        <el-table-column label="审查时间" align="center" prop="shsj"/>
        <el-table-column label="审查结果" align="center" prop="shjg">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.fs_gw_layyzt" :value="scope.row.shjg"/>
          </template>
        </el-table-column>
        <el-table-column label="审查意见" align="center" prop="shyj" width="200px"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="shcancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 证据弹出框 -->
    <el-dialog :title="zjTitle" :visible.sync="zjOpen" width="800px" append-to-body>

      <el-table :data="zjList">
        <el-table-column label="证据名称" align="center" prop="typeName" width="180px"/>
        <el-table-column label="查看文件" align="center" prop="fileName">
          <template slot-scope="scope">
            <el-link :href="scope.row.oosUrl" target="_blank" class="buttonText" type="primary" :underline="false">
              {{ scope.row.fileName }}
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="zjcancel">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="jatitle" :visible.sync="jaopen" width="600px" append-to-body>
      <el-form ref="form" :model="jaform" label-width="160px">
        <el-form-item label="案号" prop="ah">
          <el-input v-model="jaform.ah" placeholder="请输入案号"/>
        </el-form-item>
        <el-form-item label="结案方式" prop="sdzt">
          <el-select v-model="jaform.sdzt" placeholder="请选择结案类型">
            <el-option
              v-for="dict in dict.type.fs_ja_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否生成还款账单" prop="status">
          <el-radio-group v-model="jaform.ifBill">
            <el-radio
              v-for="dict in dict.type.fs_yes_no"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="jaform.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改快递信息对话框 -->
    <el-dialog :title="yjTitle" :visible.sync="yjOpen" width="600px" append-to-body>
      <el-form ref="yjform" :model="yjform" :rules="yjrules" label-width="120px">
        <el-form-item label="业务类型" prop="ywlx" required>
          <el-select v-model="yjform.ywlx" placeholder="请选择业务类型">
            <el-option
              v-for="dict in dict.type.fs_post_ywlx"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="快递公司" prop="com" required>
          <el-select v-model="yjform.com" placeholder="请选择快递公司">
            <el-option
              v-for="dict in dict.type.fs_kdgs_bm"
              :key="dict.value"
              :label="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="快递单号" prop="kddh" required>
          <el-input v-model="yjform.kddh" placeholder="请输入快递单号" @blur="handleKddhBlur"/>
        </el-form-item>
        <el-form-item label="业务状态" prop="ywzt">
          <el-select v-model="yjform.ywzt" placeholder="请选择业务状态">
            <el-option
              v-for="dict in dict.type.fs_post_ywzt"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发件时间" prop="fjsj">
          <el-date-picker clearable
                          v-model="yjform.fjsj"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择快递发件时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="签收时间" prop="qssj">
          <el-date-picker clearable
                          v-model="yjform.qssj"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择快递签收时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收件人" prop="sjr">
          <el-input v-model="yjform.sjr" placeholder="请输入收件人"/>
        </el-form-item>
        <el-form-item label="电话" prop="dh">
          <el-input v-model="yjform.dh" placeholder="请输入电话"/>
        </el-form-item>
        <el-form-item label="地址" prop="dz">
          <el-input v-model="yjform.dz" placeholder="请输入地址"/>
        </el-form-item>
        <el-form-item label="快递状态" prop="kdzt">
          <el-select v-model="yjform.kdzt" placeholder="请选择快递状态">
            <el-option
              v-for="dict in dict.type.fs_post_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="yjform.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitYjForm">确 定</el-button>
        <el-button @click="yjcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 快递信息 -->
    <el-dialog :title="yjxxTitle" :visible.sync="yjxxOpen" width="600px" append-to-body>
      <el-form ref="yjform" :model="yjform" label-width="120px">
        <el-row>
          <el-col v-if="yjform.com != null" :span="24">
            <el-form-item label="快递公司：">
              <dict-tag :options="dict.type.fs_kdgs_bm" :value="yjform.com"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="快递单号：">{{ yjform.kddh }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务类型：">
              <dict-tag :options="dict.type.fs_post_ywlx" :value="yjform.ywlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务状态：">
              <dict-tag :options="dict.type.fs_post_ywzt" :value="yjform.ywzt"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发件时间：">{{ yjform.fjsj }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签收时间：">{{ yjform.qssj }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收件人：">{{ yjform.sjr }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电话：">{{ yjform.dh }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="地址：">{{ yjform.dz }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注：">{{ yjform.remark }}</el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="yjform.kdzt != null">
          <el-col :span="24">
            <el-collapse v-model="kdxxCollapse">
              <el-collapse-item title="物流信息" name="1">
                <div>
                  <el-form-item label="物流状态：">
                    <dict-tag :options="dict.type.fs_post_status" :value="yjform.kdzt"/>
                  </el-form-item>
                </div>
                <div class="block">
                  <el-timeline :reverse="reverse">
                    <el-timeline-item
                      v-for="(activity, index) in wlxxDetail"
                      :key="index"
                      :timestamp="activity.time">
                      {{ activity.desc }}
                    </el-timeline-item>
                  </el-timeline>
                </div>
              </el-collapse-item>
            </el-collapse>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="yjxxcancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改邮寄工单对话框 -->
    <el-dialog :title="yjgdTitle" :visible.sync="yjgdOpen" width="500px" append-to-body>
      <el-form ref="yjgdform" :model="yjgdform" :rules="yjgdrules" label-width="80px">
        <el-form-item label="业务类型" prop="ywlx">
          <el-select v-model="yjgdform.ywlx" placeholder="请选择业务类型">
            <el-option
              v-for="dict in dict.type.fs_post_ywlx"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收件人" prop="sjr">
          <el-input v-model="yjgdform.sjr" placeholder="请输入收件人"/>
        </el-form-item>
        <el-form-item label="电话" prop="dh">
          <el-input v-model="yjgdform.dh" placeholder="请输入电话"/>
        </el-form-item>
        <el-form-item label="地址" prop="dz">
          <el-input v-model="yjgdform.dz" placeholder="请输入地址"/>
        </el-form-item>
        <el-form-item label="邮寄要求" prop="yjyq">
          <el-input v-model="yjgdform.yjyq" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="yjgdform.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="newYjgd">新增工单</el-button>
        <el-button v-if="ifYjgdUpdate" type="primary" @click="editYjgd">完善工单</el-button>
        <el-button @click="yjgdcancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改重提工单对话框 -->
    <el-dialog :title="ajctTitle" :visible.sync="ajctOpen" width="500px" append-to-body>
      <el-form ref="ajctform" :model="ajctform" :rules="ajctrules" label-width="80px">
        <el-form-item label="重提要求" prop="ctyq">
          <el-input v-model="ajctform.ctyq" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="ajctform.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="newAjct">新增工单</el-button>
        <el-button v-if="ifAjctUpdate" type="primary" @click="editAjct">完善工单</el-button>
        <el-button @click="ajctcancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 生成还款计划 -->
    <el-dialog :title="hkjhTitle" :visible.sync="hkjhOpen" width="800px" append-to-body>
      <el-form ref="hkform" :model="hkform" :rules="hkrules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="诉请金额">{{ hkform.sqje }}</el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="还款金额" prop="hkje">
              <el-input v-model="hkform.hkje" placeholder="还款金额"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="期数" prop="qs">
              <el-input v-model="hkform.qs" placeholder="期数"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="首次还款日" prop="schkr">
              <el-date-picker v-model="hkform.schkr" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                              :style="{width: '100%'}" placeholder="首次还款日" clearable></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button type="primary" @click="initHkjh" style="    margin-left: 100px;">生成计划</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table class="hktable" :data="hkjhList">
        <el-table-column label="序号" align="center" prop="xh"/>
        <el-table-column label="还款日期" align="center" prop="jhrq">
          <template slot-scope="scope">
            <el-date-picker v-model="scope.row.jhrq" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                            :style="{width: '100%'}" placeholder="请选择计划还款日期" clearable></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column label="还款金额" align="center" prop="jhje">
          <template slot-scope="scope">
            <el-input v-model="scope.row.jhje" placeholder="请输入计划还款金额" @focus="focusJe(scope.row.jhje)"
                      @blur="changJhje(scope.row)"/>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" width="200px">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remark" placeholder="备注"/>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="newHkjh">保 存</el-button>
        <el-button @click="hkjhcancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 查看还款计划 -->
    <el-dialog :title="hkxqTitle" :visible.sync="hkxqOpen" width="800px" append-to-body>
      <el-form ref="hkform" :model="hkform" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="还款金额" prop="hkje">
              {{ hkform.hkje }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="期数" prop="qs">
              {{ hkform.qs }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="首次还款日" prop="schkr">
              {{ hkform.schkr }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table class="hktable" :data="hkjhList">
        <el-table-column label="序号" align="center" prop="xh"/>
        <el-table-column label="计划日期" align="center" prop="jhrq">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.jhrq, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="计划金额" align="center" prop="jhje"/>
        <el-table-column label="备注" align="center" prop="remark" width="200px"/>
        <el-table-column label="状态" align="center" prop="zt">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.fs_hkjh_zt" :value="scope.row.zt"/>
          </template>
        </el-table-column>
        <el-table-column label="还款信息" align="center" prop="shrq" width="200px">
          <template slot-scope="scope">
            <template v-for="(item,index) in scope.row.pays">
              <span>{{ item.shje }}元</span>&nbsp;
              <span>{{ parseTime(item.shrq, '{y}-{m}-{d}') }}</span>&nbsp;
              <dict-tag :options="dict.type.fs_hkjh_sh" :value="item.zt"/>&nbsp;
              <br>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="hkxqcancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加法院联系信息对话框 -->
    <el-dialog :title="tjfylxTitle" :visible.sync="tjfylxOpen" width="500px" append-to-body>
      <el-form ref="fylxform" :model="fylxform" :rules="fylxrules" label-width="80px">
        <el-form-item label="是否同步">
          <el-switch v-model="fylxform.ifTb"></el-switch>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="fylxform.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="newFylx">新增记录</el-button>
        <el-button @click="tjfylxcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看还款计划 -->
    <el-dialog :title="ckfylxTitle" :visible.sync="ckfylxOpen" width="800px" append-to-body>
      <el-table class="fylxtable" :data="fylxList">
        <el-table-column label="记录时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="记录人" align="center" prop="createBy"/>
        <el-table-column label="备注" align="center" prop="remark" width="300px"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="ckfylxcancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改案件进展对话框 -->
    <el-dialog :title="jzTitle" :visible.sync="jzOpen" width="800px" append-to-body>
      <el-form ref="jzform" :model="jzform" :rules="jzrules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="进展类型" prop="jzlx">
              <el-select v-model="jzform.jzlx" placeholder="请选择进展类型" @change="handleChangeJzlx">
                <el-option
                  v-for="dict in dict.type.fs_aj_jzlx"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="jzform.jzlx==4">
          <el-row>
            <el-col :span="12">
              <el-form-item label="开庭方式" prop="ktfs">
                <el-select v-model="jzform.ktfs" placeholder="请选择开庭方式">
                  <el-option
                    v-for="dict in dict.type.fs_aj_ktlx"
                    :key="dict.value"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开庭时间" prop="ktrq">
                <el-date-picker clearable
                                v-model="jzform.ktrq"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择开庭日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-time-picker v-model="jzform.ktsj" format="HH:mm" value-format="HH:mm"
                              :picker-options='{"selectableRange":"00:00:00-23:59:59"}' :style="{width: '100%'}"
                              placeholder="开庭时间" clearable></el-time-picker>
            </el-col>
            <el-col :span="12">
              <el-form-item label="法庭" prop="ft">
                <el-input v-model="jzform.ft" placeholder="请输入法庭"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="案号" prop="fgxx">
                <el-input v-model="jzform.ah" placeholder="请输入案号"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="法官信息" prop="fgxx">
                <el-input v-model="jzform.fgxx" placeholder="请输入法官信息"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="开庭短信" prop="ktdx">
                <el-input v-model="jzform.ktdx" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="传票信息" prop="ktcpxx">
                <el-input v-model="jzform.ktcpxx" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="小程序" prop="xcxxx">
                <el-input v-model="jzform.xcxxx" type="textarea" placeholder="请输入线上小程序信息"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="调解方案" prop="tjfa">
                <el-input v-model="jzform.tjfa" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div v-if="jzform.jzlx!=4">
          <el-form-item label="日期" prop="rq">
            <el-date-picker clearable
                            v-model="jzform.rq"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="请选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="重点信息" prop="zdxx">
            <el-input v-model="jzform.zdxx" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
        </div>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="jzform.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitJzForm">确 定</el-button>
        <el-button @click="jzcancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {Div, Add, Sub, Mul, formatDate, formatNumber, toChineseNumber} from "@/api/fs/common";
import {
  listCase,
  getCase,
  delCase,
  addCase,
  updateCase,
  listSh,
  ja,
  listTjy,
  listFile,
  listSf,
  listChild,
  listZf,
  listBatch,
  listSszt,
  addExpress,
  getExpressByKddh,
  getPostByCaseId,
  addPost,
  updatePost,
  getPushByCaseId,
  addPush,
  updatePush, getRepaymentByCaseId, getCourtContact
} from "@/api/fs/case";
import {addRepayment} from "@/api/fs/repayment";
import {addContact} from "@/api/fs/contact";
import {addOpencourt} from "@/api/fs/opencourt";
import {getProcessByCaseAndLx} from "@/api/fs/progress";

export default {
  name: "Case",
  dicts: ['sys_user_sex', 'fs_gw_dsrlx', 'fs_gw_dzlx', 'fs_gw_layyzt', 'fs_gw_ajzt', 'fs_gw_ajlx', 'fs_ja_type',
    'fs_gw_mz', 'fs_gw_zy', 'fs_gw_sqlx', 'fs_gw_dwxz', 'fs_gw_zzlx', 'fs_gw_zjlx', 'fs_yes_no', 'fs_post_ywlx',
    'fs_post_ywzt', 'fs_post_status', 'fs_lafs', 'fs_kdgs_bm', 'fs_hkjh_zt', 'fs_hkjh_sh', 'fs_aj_jzlx', 'fs_aj_ktlx'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 遮罩层
      shLoading: false,
      zjLoading: false,
      reverse: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 案件信息表格数据
      caseList: [],
      shList: [],
      zjList: [],
      hkjhList: [],
      fylxList: [],
      tjyOptions: [],
      sfOptions: [],
      dsOptions: [],
      qxOptions: [],
      zfOptions: [],
      pcOptions: [],
      ssztOptions: [],
      // 弹出层标题
      title: "",
      shTitle: "",
      zjTitle: "",
      yjTitle: "",
      yjxxTitle: "",
      yjgdTitle: "",
      ajctTitle: "",
      hkjhTitle: "",
      hkxqTitle: "",
      tjfylxTitle: "",
      ckfylxTitle: "",
      jzTitle: "",
      // 是否显示弹出层
      open: false,
      shOpen: false,
      zjOpen: false,
      yjOpen: false,
      yjxxOpen: false,
      yjgdOpen: false,
      ajctOpen: false,
      hkjhOpen: false,
      hkxqOpen: false,
      tjfylxOpen: false,
      ckfylxOpen: false,
      jzOpen: false,
      ifYjgdUpdate: false,
      ifAjctUpdate: false,
      jatitle: "",
      jaopen: false,
      oldJhje: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ah: null,
        yg: null,
        bg: null,
        ajlx: null,
        ajmc: null,
        fyid: null,
        sqbdje: null,
        sqlaay: null,
        zt: null,
        cjsj: null,
        gxsj: null,
        ownerId: null,
        ajzt: null,
        tjyId: null,
        sfid: null,
        sid: null,
        qxid: null,
        zfid: null,
        batchId: null,
        nbajbh: null,
        ssztid: null,
        lafs: null,
        ifPost: null,
        ifRepayment: null,
      },
      activeNames: ['1', '2', '3'],
      kdxxCollapse: [],
      wlxxDetail: [],
      // 表单参数
      form: {},
      jaform: {},
      yjform: {},
      yjgdform: {},
      ajctform: {},
      hkform: {},
      fylxform: {},
      jzform: {},
      ygDsr: {},
      bgDsr: {},
      // 表单校验
      rules: {
        ajlx: [
          {required: true, message: "案件类型不能为空", trigger: "change"}
        ],
      },
      yjrules: {
        kddh: [
          {required: true, message: "快递单号不能为空", trigger: "change"}
        ],
        com: [
          {required: true, message: "快递公司不能为空", trigger: "change"}
        ],
        ywlx: [
          {required: true, message: "业务类型不能为空", trigger: "change"}
        ],
      },
      yjgdrules: {
        ywlx: [
          {required: true, message: "业务类型不能为空", trigger: "change"}
        ],
        sjr: [
          {required: true, message: "收件人不能为空", trigger: "change"}
        ],
        dz: [
          {required: true, message: "收件地址不能为空", trigger: "change"}
        ],
        dh: [
          {required: true, message: "电话不能为空", trigger: "change"}
        ],
      },
      ajctrules: {},
      hkrules: {
        hkje: [
          {required: true, message: "还款金额不能为空", trigger: "change"}
        ],
        qs: [
          {required: true, message: "期数不能为空", trigger: "change"}
        ],
        schkr: [
          {required: true, message: "首次还款日不能为空", trigger: "change"}
        ],
      },
      fylxrules: {},
      jzrules: {
        jzlx: [
          {required: true, message: "进展类型不能为空", trigger: "change"}
        ],
        ktfs: [
          {required: true, message: "开庭方式不能为空", trigger: "change"}
        ],
        ktrq: [
          {required: true, message: "开庭日期不能为空", trigger: "change"}
        ],
        ktsj: [
          {required: true, message: "开庭时间不能为空", trigger: "change"}
        ],
      },
    };
  },
  created() {
    this.getList();
    this.reset();
    this.getTjy();
    this.getSf();
    this.getZf();
    this.getSszt();
  },
  methods: {
    /** 查询案件信息列表 */
    getList() {
      this.loading = true;
      listCase(this.queryParams).then(response => {
        this.caseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getZf() {
      listZf().then(response => {
        this.zfOptions = response.data;
      });
    },
    getTjy() {
      listTjy().then(response => {
        this.tjyOptions = response.data;
      });
    },
    getSszt() {
      listSszt().then(response => {
        this.ssztOptions = response.data;
      });
    },
    getSf() {
      listSf().then(response => {
        this.sfOptions = response.data;
      });
    },
    getDs() {
      this.queryParams.sid = null;
      this.queryParams.qxid = null;
      this.dsOptions = [];
      this.qxOptions = [];
      this.handleQuery();
      if (this.queryParams.sfid && this.queryParams.sfid > 0) {
        listChild(this.queryParams.sfid).then(response => {
          this.dsOptions = response.data;
        });
      }
    },
    getQx() {
      this.queryParams.qxid = null;
      this.qxOptions = [];
      this.handleQuery();
      if (this.queryParams.sid && this.queryParams.sid > 0) {
        listChild(this.queryParams.sid).then(response => {
          this.qxOptions = response.data;
        });
      }
    },
    getBatch() {
      this.queryParams.batchId = null;
      this.pcOptions = [];
      this.handleQuery();
      if (this.queryParams.zfid && this.queryParams.zfid > 0) {
        listBatch(this.queryParams.zfid).then(response => {
          this.pcOptions = response.data;
        });
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.jaopen = false;
      this.reset();
    },
    shcancel() {
      this.shOpen = false;
    },
    zjcancel() {
      this.zjOpen = false;
    },
    yjcancel() {
      this.yjOpen = false;
      this.resetYj();
    },
    yjxxcancel() {
      this.yjxxOpen = false;
      this.resetYj();
    },
    yjgdcancel() {
      this.yjgdOpen = false;
      this.resetYj();
    },
    ajctcancel() {
      this.ajctOpen = false;
      this.resetAjct();
    },
    hkjhcancel() {
      this.hkjhOpen = false;
      this.resetHk();
    },
    hkxqcancel() {
      this.hkxqOpen = false;
      this.resetHk();
    },
    tjfylxcancel() {
      this.tjfylxOpen = false;
      this.resetFylx();
    },
    ckfylxcancel() {
      this.ckfylxOpen = false;
    },
    jzcancel() {
      this.jzOpen = false;
      this.resetJz();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        localId: null,
        bh: null,
        ah: null,
        bhLs: null,
        yg: null,
        ygbh: null,
        bg: null,
        bgbh: null,
        ajlx: null,
        ajlxMc: null,
        ajmc: null,
        bzqx: null,
        fyid: null,
        fymc: null,
        dzlx: null,
        sqbdje: null,
        sqlaay: null,
        sqlx: null,
        sqlxMc: null,
        zt: null,
        cjsj: null,
        gxsj: null,
        ownerId: null,
        owner: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        ajzt: null,
        tjyId: null
      };
      this.ygDsr = {
        id: null,
        localId: null,
        bh: null,
        dsrlx: null,
        xm: null,
        xb: null,
        nl: null,
        mz: null,
        csrq: null,
        dzlx: null,
        dz: null,
        dwmc: null,
        zy: null,
        zymc: null,
        gzdw: null,
        dwxz: null,
        zzlx: null,
        zzh: null,
        zybsjgszd: null,
        fddbr: null,
        fddbrzw: null,
        zjlx: null,
        zjhm: null,
        sjhm: null,
        gddh: null,
        cjsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.bgDsr = {
        id: null,
        localId: null,
        bh: null,
        dsrlx: null,
        xm: null,
        xb: null,
        nl: null,
        mz: null,
        csrq: null,
        dzlx: null,
        dz: null,
        dwmc: null,
        zy: null,
        zymc: null,
        gzdw: null,
        dwxz: null,
        zzlx: null,
        zzh: null,
        zybsjgszd: null,
        fddbr: null,
        fddbrzw: null,
        zjlx: null,
        zjhm: null,
        sjhm: null,
        gddh: null,
        cjsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.jaform = {
        id: null,
        ah: null,
        sdzt: null,
        ifBill: null,
        remark: null
      }
      this.resetForm("form");
    },
    resetYj() {
      this.yjform = {
        id: null,
        caseId: null,
        com: null,
        kddh: null,
        sjr: null,
        dh: null,
        dz: null,
        ywlx: null,
        ywzt: null,
        kdzt: null,
        fjsj: null,
        gxsj: null,
        qhsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("yjform");
    },
    resetYjgd() {
      this.yjgdform = {
        id: null,
        caseId: null,
        nbajbh: null,
        ajmc: null,
        ywlx: null,
        sjr: null,
        dh: null,
        dz: null,
        yjyq: null,
        zt: null,
        cjr: null,
        ssr: null,
        fpsj: null,
        wcsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("yjgdform");
    },
    resetAjct() {
      this.ajctform = {
        id: null,
        caseId: null,
        nbajbh: null,
        ajmc: null,
        ctyq: null,
        zt: null,
        cjr: null,
        ssr: null,
        fpsj: null,
        wcsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("ajctform");
    },
    resetHk() {
      this.hkform = {
        id: null,
        caseId: null,
        hkje: null,
        qs: null,
        schkr: null,
        sqje: null,
      };
      this.resetForm("hkform");
      this.hkjhList = []
    },
    resetFylx() {
      this.fylxform = {
        id: null,
        caseId: null,
        ifTb: false,
        remark: null,
      };
      this.resetForm("fylxform");
    },
    resetJz() {
      this.jzform = {
        id: null,
        caseId: null,
        jzlx: null,
        rq: null,
        cjr: null,
        zdxx: null,
        ah: null,
        fyid: null,
        fymc: null,
        ft: null,
        ktfs: null,
        ktrq: null,
        ktsj: null,
        tjy: null,
        fgxx: null,
        dllsid: null,
        dlls: null,
        lszjUrl: null,
        ktdx: null,
        ktcpxx: null,
        ktcpUrl: null,
        xcxxx: null,
        tjfa: null,
        zjzb: null,
        remark: null
      };
      this.resetForm("jzform");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.sfid = null;
      this.queryParams.sid = null;
      this.queryParams.qxid = null;
      this.queryParams.zfid = null;
      this.queryParams.batchId = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getCase(id).then(response => {
        this.form = response.data;
        this.ygDsr = response.data.ygDsr;
        this.bgDsr = response.data.bgDsr;
        this.open = true;
        this.title = "案件信息";
      });
    },
    handleYj(row) {
      this.resetYj();
      this.yjform.caseId = row.id;
      this.yjOpen = true;
      this.yjTitle = "添加快递信息";
    },
    handleYjgd(row) {
      const id = row.id
      this.resetYjgd();
      getPostByCaseId(id).then(response => {
        let data = response.data;
        if (data != null) {
          this.yjgdform = data;
          this.ifYjgdUpdate = true;
        } else {
          this.ifYjgdUpdate = false;
        }
        this.yjgdform.caseId = row.id;
        this.yjgdOpen = true;
        this.yjgdTitle = "添加邮寄工单";
      });
    },
    handleAjct(row) {
      const id = row.id
      this.resetAjct();
      getPushByCaseId(id).then(response => {
        let data = response.data;
        if (data != null) {
          this.ajctform = data;
          this.ifAjctUpdate = true;
        } else {
          this.ifAjctUpdate = false;
        }
        this.ajctform.caseId = row.id;
        this.ajctOpen = true;
        this.ajctTitle = "添加案件重提工单";
      });
    },
    handleZjcl(row) {
      this.reset();
      const id = row.id || this.ids
      listFile(id).then(response => {
        this.zjList = response.data;
        this.zjOpen = true;
        this.zjTitle = "证据材料";
      });
    },
    /** 修改按钮操作 */
    handleSh(row) {
      this.reset();
      const id = row.id || this.ids
      listSh(id).then(response => {
        this.shList = response.data;
        this.shOpen = true;
        this.shTitle = "审查信息";
      });
    },
    /** 结案按钮操作 */
    handleJa(row) {
      const id = row.id || this.ids
      this.jaform.id = id;
      this.jaform.ah = row.ah;
      this.jaopen = true;
      this.jatitle = "手动结案";
    },
    /** 提交按钮 */
    submitForm() {
      ja(this.jaform).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.jaopen = false;
        this.getList();
      });
    },
    /** 导出按钮操作 */
    handleExportNwd() {
      let zf = this.zfOptions.find(option => option.id === this.queryParams.zfid);

      let fileName = "";
      if (zf != null) {
        fileName = zf.name + "-";
      }
      if (this.queryParams.batchId != null) {
        const batchName = this.pcOptions.find(option => option.id === this.queryParams.batchId).batchName;
        fileName += batchName + "-";
      }
      fileName += "案件跟进信息"
      var dt = new Date();
      let year = dt.getFullYear();
      let month = (dt.getMonth() + 1).toString().padStart(2, '0');
      let date = dt.getDate().toString().padStart(2, '0');
      fileName += "-" + year + "/" + month + "/" + date + ".xlsx";
      this.download('fs/case/exportNwd', {
        ...this.queryParams
      }, fileName)
    },
    handleExport() {
      this.download('fs/case/export', {
        ...this.queryParams
      }, `case_${new Date().getTime()}.xlsx`)
    },
    /** 提交按钮 */
    submitYjForm() {
      this.$refs["yjform"].validate(valid => {
        if (valid) {
          addExpress(this.yjform).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.yjopen = false;
            this.getList();
          });
        }
      });
    },
    handleKddhBlur() {
      let dh = this.yjform.kddh;
      let caseId = this.yjform.caseId;
      getExpressByKddh(dh).then(response => {
        let data = response.data;
        if (data != null) {
          data.caseId = caseId;
          this.yjform = data;
        }
      });
    },
    handleYjxx(row) {
      this.resetYj();
      this.yjxxOpen = true;
      this.yjxxTitle = "快递信息";
      this.yjform = row.lastExpress;
      if (this.yjform != null && this.yjform.wlxx != null) {
        let wlxx = this.yjform.wlxx;
        let obj = eval(wlxx);
        this.wlxxDetail = obj;
      }
      this.yjform.caseId = row.id;
    },
    newYjgd() {
      this.$refs["yjgdform"].validate(valid => {
        if (valid) {
          addPost(this.yjgdform).then(response => {
            this.$modal.msgSuccess("邮寄工单新增成功！");
            this.yjgdOpen = false;
            this.getList();
          });
        }
      });
    },
    editYjgd() {
      this.$refs["yjgdform"].validate(valid => {
        if (valid) {
          updatePost(this.yjgdform).then(response => {
            this.$modal.msgSuccess("邮寄工单更新成功！");
            this.yjgdOpen = false;
            this.getList();
          });
        }
      });
    },
    newAjct() {
      addPush(this.ajctform).then(response => {
        this.$modal.msgSuccess("案件重提工单新增成功！");
        this.ajctOpen = false;
      });
    },
    editAjct() {
      updatePush(this.ajctform).then(response => {
        this.$modal.msgSuccess("案件重提工单更新成功！");
        this.ajctOpen = false;
      });
    },
    handleAddHkjh(row) {
      this.resetHk();
      this.hkjhOpen = true;
      this.hkform.caseId = row.id;
      this.hkform.sqje = (row.sqbdje * 10000).toFixed(2);
      this.hkjhTitle = "生成还款计划";
    },
    initHkjh() {
      this.$refs["hkform"].validate(valid => {
        if (valid) {
          let hkje = this.hkform.hkje;
          let qs = parseInt(this.hkform.qs);
          let schkr = this.hkform.schkr;
          let pje = Div(hkje, qs).toFixed(2);
          let last = Sub(hkje, Mul(pje, Sub(qs, 1)));
          const date = new Date(schkr);
          date.setMonth(date.getMonth() - 1);
          const list = [];
          for (let i = 0; i < qs; i++) {
            let jhrq = date.setMonth(date.getMonth() + 1);
            let time = formatDate(jhrq, 'yyyy-MM-dd');
            let jhje = pje;
            if (i == (qs - 1)) {
              jhje = last;
            }
            jhje = formatNumber(jhje);
            let remark = "第" + toChineseNumber(i + 1) + "期";
            if (i == (qs - 1)) {
              remark += "结清";
            }
            let jh = {
              xh: i + 1,
              jhrq: time,
              jhje: jhje,
              remark: remark
            };
            list[i] = jh;
          }
          this.hkjhList = list;
        }
      });
    },
    focusJe: function (jhje) {
      this.oldJhje = jhje;
    },
    changJhje: function (row) {
      if (row.jhje == this.oldJhje) {
        return;
      }
      let list = this.hkjhList;
      let hkje = this.hkform.hkje;
      let qs = parseInt(this.hkform.qs);
      let indx = row.xh;
      let tcount = 0;
      let tnum = 0
      for (let i = 0; i < qs; i++) {
        let jh = list[i];
        let nindx = jh.xh;
        if (nindx <= indx) {
          tnum++;
          tcount = Add(tcount, jh.jhje);
        }
      }
      let scount = Sub(hkje, tcount);
      let sqs = Sub(qs, tnum);
      let pje = Div(scount, sqs).toFixed(2);
      let last = Sub(scount, Mul(pje, Sub(sqs, 1)));
      for (let i = tnum; i < qs; i++) {
        let jhje = pje;
        if (i == (qs - 1)) {
          jhje = last;
        }
        list[i].jhje = formatNumber(jhje);
      }
      this.hkjhList = list;
    },
    newHkjh() {
      this.hkform.hkjhList = this.hkjhList;
      addRepayment(this.hkform).then(response => {
        this.$modal.msgSuccess("还款计划新增成功！");
        this.hkjhOpen = false;
        this.getList();
      });
    },
    handleViewHkjh(row) {
      this.resetHk();
      getRepaymentByCaseId(row.id).then(response => {
        let data = response.data;
        this.hkform = data;
        let hkjhList = data.hkjhList;
        for (let i = 0; i < hkjhList.length; i++) {
          hkjhList[i].jhje = formatNumber(hkjhList[i].jhje.toFixed(2));
          hkjhList[i].shje = formatNumber(hkjhList[i].shje.toFixed(2));
        }
        this.hkjhList = hkjhList;
        this.hkxqOpen = true;
        this.hkxqTitle = "还款计划详情";
      });

    },
    handleAddFylxjl(row) {
      this.resetFylx();
      this.tjfylxOpen = true;
      this.fylxform.caseId = row.id;
      this.tjfylxTitle = "添加法院沟通记录";
    },
    newFylx() {
      addContact(this.fylxform).then(response => {
        this.$modal.msgSuccess("法院沟通信息新增成功！");
        this.tjfylxOpen = false;
        this.getList();
      });
    },
    handleViewFylxjl(row) {
      getCourtContact(row.id).then(response => {
        this.fylxList = response.data;
        this.ckfylxOpen = true;
        this.ckfylxTitle = "查看法院沟通记录";
      });

    },
    handleProcess(row) {
      this.resetJz();
      this.jzform.caseId = row.id;
      this.jzOpen = true;
      this.jzTitle = "添加进展";
    },
    submitJzForm() {
      this.$refs["jzform"].validate(valid => {
        if (valid) {
          if (this.jzform.jzlx == 4) {
            addOpencourt(this.jzform).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.jzOpen = false;
              // this.getList();
            });
          }
        }
      });
    },
    handleChangeJzlx() {
      let caseId = this.jzform.caseId;
      let jzlx = this.jzform.jzlx;
      getProcessByCaseAndLx(caseId, jzlx).then(response => {
        if (response.data && response.data != null) {
          this.jzform = response.data;
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.detail .el-form-item {
  margin-bottom: 0px;
}

h3 {
  font-family: inherit;
  font-weight: 500;
  line-height: 1.1;
  color: inherit;
  background: #e6ebf5;
  padding: 10px;
  margin: 10px 0;
}

.el-collapse-item__header {
  font-size: 16px !important;
  font-weight: 600 !important;
}

.el-table__cell .cell div {
  display: inline;
}

.el-table__cell .cell .btn {
  cursor: pointer;
}

.cellBtn button {
  font-size: 20px !important;
  padding: 0 !important;
}

.hktable .el-table__cell .cell div {
  display: inline-block;
}
</style>
